1. Field of the Invention
The present invention is directed to computer systems; and more particularly, it is directed to rendering artwork including semi-transparent surfaces using computer systems.
2. Description of the Related Art
As the power and complexity of personal computer systems increase, graphics operations and graphical data are likewise increasing in complexity. For example, an instance of three-dimensional (3-D) artwork may include numerous layers of graphical data. The layers may be related in complex ways based on their relative depth as well as their transparency properties. The layers may also be referred to as surfaces. It is desirable to render artwork containing such layers (e.g., for display on a display device) both correctly and efficiently.
A typical problem encountered when rendering 3-D artwork is “hidden surface” removal, which involves finding the nearest surface at each pixel. Because the image is created using only the color of the nearest shaded surface at each pixel, hidden surface removal produces a realistic depiction of opaque objects.
One technique for rendering hidden surfaces involves sorting the triangles which make up the surface so that the nearest triangles are rendered last when rasterizing the triangles. This geometry sorting technique may be referred to as an “object space sort.” Unfortunately, this technique may be inefficient for complex models containing intersecting surfaces, e.g., where the triangles that make up a surface are broken up into smaller pieces.
Another technique for hidden surface removal stores the depth value (Z-value) at each pixel sample. This technique may be referred to as an “image-based sort.” The Z-value is initialized to a suitably far value, and the surfaces are then rasterized to compute the surface Z-value at each pixel. If the surface Z-value is smaller than the Z-value for the pixel sample, then the pixel color and pixel Z-value are replaced with the surface color and surface Z-value.
A “Z-buffer” technique is a method for rendering opaque surfaces in modern graphics hardware. The Z-buffer is part of an off-screen memory that stores the depth of each pixel or the distance (i.e., the Z-value) of each pixel from the viewpoint. When using the Z-buffer technique to render images, however, aliasing artifacts may result on edges of the geometry. Modern graphics hardware may address the aliasing problem in several ways. One technique involves rendering the image to an off-screen buffer that is larger than the final displayed image and then filtering down the result. Another technique involves rendering the image several times, slightly “jittering” the camera each time, and averaging the resulting images to reduce the aliasing artifacts. A solution referred to as “full-screen anti-aliasing” may use multiple color and Z-samples (i.e., sub-pixels) for each pixel.
A modern graphics processing unit (GPU) typically runs small programs called “pixel shaders” to compute the surface color and the alpha values for each pixel based on texture values. Pixel shaders may be relatively expensive to execute. One optimization used in full-screen anti-aliasing is to compute the pixel shader once per pixel then use the resulting color and the alpha value for each of the sub-pixels when performing Z-buffering. The Z-value may then be interpolated correctly for each sub-pixel from the geometry to allow for anti-aliased intersections to be rendered correctly.
A blending function referred to as “over” may be used in representing surfaces in 3-D scenes. A vertex or pixel in a surface may be described by an opaque color along with at least one transparency value. The surface transparency value may directly scale the amount of light coming through the surface, and one minus the transparency value may scale the opaque color before adding the result to the pixel. To simplify subsequent calculations, the surface color may be defined as the pre-multiplied surface color (i.e., the surface opaque color value) multiplied by one minus the surface transparency value. The formula for the over operator may be represented by the following equation (1), where the colors are for the pixel before and after compositing of the Nth surface:CpixelN=CsurfaceN+TsurfaceN*CpixelN-1  (1)
One technique to compute the final color arising from a stack of transparent surfaces is to sort them in order of depth value (Z-value) and then apply equation (1) from back to front. When the scene also includes opaque surfaces, the nearest opaque surface is first used to set the color of the pixel. Any transparent surfaces behind the nearest opaque surface are discarded since they are obscured by the opaque surface. This technique is referred to as “back-to-front compositing.”
Another technique is to operate on the surfaces in front to back order. In addition to the pixel color, a transparency value is kept at each pixel sample. This pixel transparency is initially set to one. For subsequent surfaces, the values of the pixel sample transparency and pixel sample color are modified using equations (2) and (3):CpixelN=TpixelN-1CsurfaceN+CpixelN-1  (2)TpixelN=TpixelN-1TsurfaceN  (3)
To avoid sorting the surfaces before rendering, a technique referred to as “layer peeling” may be used during rasterization. Layer peeling may render the geometry multiple times using two Z-buffers to compute the nearest surface, the next nearest surface, and so on. A drawback of the layer peeling technique is the need for a second Z-buffer. On modern graphics hardware, a depth texture can be used to store the depth value (Z-value) of the Z-buffer. Originally designed for Z-buffered shadows, the depth texture test allows one sample per pixel and returns the result of testing a depth value against the contents of a pixel. However, given the sample constraint on depth textures, layer peeling is currently incompatible with full-screen anti-aliasing.